Fix god mode advice
authorJunpeng Qiu <qjpchmail@gmail.com>
Wed, 27 Apr 2016 18:45:41 +0000 (14:45 -0400)
committerJunpeng Qiu <qjpchmail@gmail.com>
Wed, 27 Apr 2016 18:45:41 +0000 (14:45 -0400)
See https://github.com/justbur/emacs-which-key/pull/115

which-key.el

index fcb762809f5089e2ba1f2a357fbe72cffdf2512e..6788d0168af92e2ac9a1b854f988427952db26b5 100644 (file)
@@ -519,12 +519,12 @@ problems at github.")
   "Holds key string to use for god-mode support.")
 
 (defadvice god-mode-lookup-command
-    (before which-key--god-mode-lookup-command-advice disable)
-  (setq which-key--god-mode-key-string (ad-get-arg 0)))
-
-(defadvice god-mode-self-insert
-    (after which-key--god-mode-self-insert-advice disable)
-  (which-key--hide-popup))
+    (around which-key--god-mode-lookup-command-advice disable)
+  (setq which-key--god-mode-key-string (ad-get-arg 0))
+  (unwind-protect
+      ad-do-it
+    (when (bound-and-true-p which-key-mode)
+      (which-key--hide-popup))))
 
 (defun which-key-enable-god-mode-support (&optional disable)
   "Enable support for god-mode if non-nil. This is experimental,
@@ -533,21 +533,13 @@ problems at github. If DISABLE is non-nil disable support."
   (interactive "P")
   (setq which-key--god-mode-support-enabled (null disable))
   (if disable
-      (progn
-        (ad-disable-advice
-         'god-mode-lookup-command
-         'before 'which-key--god-mode-lookup-command-advice)
-        (ad-disable-advice
-         'god-mode-self-insert
-         'after 'which-key--god-mode-self-insert-advice))
+      (ad-disable-advice
+       'god-mode-lookup-command
+       'around 'which-key--god-mode-lookup-command-advice)
     (ad-enable-advice
      'god-mode-lookup-command
-     'before 'which-key--god-mode-lookup-command-advice)
-    (ad-enable-advice
-     'god-mode-self-insert
-     'after 'which-key--god-mode-self-insert-advice))
-  (ad-activate 'god-mode-lookup-command)
-  (ad-activate 'god-mode-self-insert))
+     'around 'which-key--god-mode-lookup-command-advice))
+  (ad-activate 'god-mode-lookup-command))
 
 ;;;###autoload
 (define-minor-mode which-key-mode